import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
//0.引入全局css
import '@/assets/global.css'
//引入his-untils.js文件
import {getDictData} from '@/utils/his-utils'
//1.导入axios
import axios from "axios";
Vue.config.productionTip = false

Vue.prototype.getDictData=getDictData

//2.设置请求拦截器
axios.interceptors.request.use(config=>{
       var token = sessionStorage.getItem("token");
       if(token){
           config.headers.token=token;
       }
       return config;
})

//3.前置路由守卫
router.beforeEach((to, from, next) => {
      var path = to.path;
      if(path==="/"||path==="/login"){
           next();
      }else{
          var token = sessionStorage.getItem("token");
          if(token){
             next();
          }else{
             next("/login");
          }
      }
})

//4. 设置axios固定的请求路径
axios.defaults.baseURL="http://localhost:7000"

//5. 把axios挂载到Vue对象
Vue.prototype.$http=axios;


new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
